package com.example.petcare.controller.user;

import com.example.petcare.pojo.Goods;
import com.example.petcare.pojo.Result;
import com.example.petcare.service.BuyService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController//标记为控制器类,并且返回json数据
@RequestMapping("/user")//请求路径
@Slf4j
public class BuyController {


    @Autowired
    private BuyService buyservice;

    // 查看增值商品列表
    @GetMapping("/getGoodsList")
    public Result<List<Goods>> GoodsList(@RequestParam("hostId") Integer hostId) {

        List<Goods> glist = buyservice.getGoodsList(hostId);

        return Result.success(glist);
    }


    // 购买增值商品，讲将增值商品添加到购物车
    @GetMapping("/addGoodsToCart")
    public Result addGoodsToCart(@RequestParam("gId") Integer gId,
                                 @RequestParam("hostId") Integer hostId) {
        buyservice.addGoodsToCart(gId, hostId);
        return Result.success();
    }

    // 查询自己买了什么增值服务
    @GetMapping("/getGoodsInCart")
    public Result<List<Goods>> getGoodsInCart(@RequestParam("hostId") Integer hostId) {
        List<Goods> glist = buyservice.getGoodsInCart(hostId);
        return Result.success(glist);
    }


    // 查询购物车中指定的gId是否存在
    @GetMapping("/checkGoodsInCart")
    public Result<Integer> checkGoodsInCart(@RequestParam("gId") Integer gId,
                                             @RequestParam("hostId") Integer hostId) {
        Integer count = buyservice.checkGoodsInCart(gId, hostId);
        return Result.success(count);
    }

}
